package senior.ioExer3;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;

/**
 * @author shkstart
 * @creat 2022-04-14:20
 */
public class MatchName {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入姓名：");
        String name = sc.next();
        BufferedReader br = null;

        try {
            br = new BufferedReader(new FileReader("C:\\Users\\rosekon\\Documents\\Tencent Files\\1716425574\\FileRecv\\baijiaxing.txt"));
            HashSet<String> hashSet = new HashSet<>();
            String s;
            while ((s = br.readLine()) != null) {
                hashSet.add(s);
            }
            for (int i = 1; i >= 0 ; i--) {
                String firstName = name.substring(0, (i + 1));
                String lastName = name.substring((i + 1));
                //System.out.println(firstName + "\t" + lastName);
                Iterator<String> iterator = hashSet.iterator();
                while (iterator.hasNext()) {
                    String next = iterator.next();
                    if(firstName.equals(next)){
                        System.out.println("姓：" + firstName + ",名：" + lastName);
                        return;
                    }
                }

            }
            System.out.println("没有这个姓");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(br != null){
                    br.close();
                }

            } catch (IOException e) {
                e.printStackTrace();
            }
        }



    }
}
